import request from "@/utils/request";
import type { MachineDTO, MachinePageQry, PageDTO, R } from "@/types";
import { type MachineSaveCmd, MachineBatchDeleteCmd } from "@/types";
import qs from "qs";

function getMachinePage(qry: MachinePageQry): Promise<R<PageDTO<MachineDTO>>> {
  return request.get("/api/machine/page", {
    params: qry,
    paramsSerializer: (params) => {
      return qs.stringify(params, { indices: false });
    }
  });
}

function saveMachine(cmd: MachineSaveCmd): Promise<R<string>> {
  return request.post("/api/machine/save", cmd);
}

function deleteMachine(id: string): Promise<R<string>> {
  return request.post("/api/machine/delete", {}, {
    params: { id }
  });
}

function getMachine(id: string): Promise<R<MachineDTO>> {
  return request.get("/api/machine/get-by-id", { params: { id } });
}

function batchDelete(cmd: MachineBatchDeleteCmd): Promise<R<string>> {
  return request.post("/api/machine/batch-delete", cmd);
}

export default {
  getMachinePage,
  saveMachine,
  deleteMachine,
  getMachine,
  batchDelete
};
